package com.lost.octopus.es.helper.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 日期工具
 * @author zhangbh
 * @date 2025/9/16 14:58
 */
public class DateUtil {

    public static final String DATETIME_FORMAT_STR = "yyyy-MM-dd HH:mm:ss";

    public static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern(DATETIME_FORMAT_STR);

    public static String toString(LocalDate date) {
        if (date == null) {
            return null;
        }
        return date.format(DateTimeFormatter.ISO_DATE);
    }

    public static String toString8(LocalDate date) {
        if (date == null) {
            return null;
        }
        return "" + date.getYear() + date.getMonthValue() + date.getDayOfMonth();
    }

    public static String toString(LocalDateTime dateTime) {
        if (dateTime != null) {
            return dateTime.format(DATETIME_FORMAT);
        }
        return null;
    }
}
